'''
* This file is part of the Chinchon (https://notabug.org/alkeon/chinchon.
* Copyright (c) 2020 Alejandro "alkeon" Castilla.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
'''

from card import Card
from random import shuffle

class Deck:
    def __init__(self, provided_list = list()):
        if(len(provided_list) < 1):
            self.cards = list()
            temporal_deck = sum(list(map( lambda n: [str(n)+'🗡',str(n)+'🏏',str(n)+'🥇',str(n)+'🍷'], [1,2,3,4,5,6,7,8,9,10,11,12])),[])
            shuffle(temporal_deck)
            i = 0
            while(i < len(temporal_deck)):
                card = temporal_deck[i]
                self.cards.append(Card(int(card[:-1]), card[-1:]))
                i += 1
        else:
            self.cards = provided_list

    def insert(self,position, card):
        self.cards.insert(position, card)

    def top(self):
        return self.cards[0]

    def get(self, position):
        return self.cards[position]

    def add_cards(self, deck):
        self.cards += deck.copy()

    def get_top_and_pop(self):
        card = self.cards[0]
        self.cards.pop(0)
        return card

    def pop(self, position):
        self.cards.pop(position)

    def shuffle(self):
        shuffle(self.cards)

    def size(self):
        return len(self.cards)
    
    def clear(self):
        self.cards.clear()

    def get_cards(self):
        return self.cards.copy()

    def ___str__(self):
        i = 0
        string_result = string()
        while(i < self.size()):
            string_result += str(i) + " " + self.get(i)
            i += 1
        return string_result
